{template 'web/'.$cfg['floder'].'/base_menu'}
<div class="top_tab">
    <a href="{php echo $this->createWebUrl('print',array('op'=>'display'))}" class="layui-btn {if $operation!='display'}layui-btn-primary{/if}">打印模板管理</a>
    <a href="{php echo $this->createWebUrl('print',array('op'=>'post'))}" class="layui-btn {if $operation!='post'}layui-btn-primary{/if}">编辑模板</a>
</div>
<style>
    .panelbox-head i{ color:#009688;}
    .panelbox-head a{ display:inline-block; margin-right:10px}
</style>
{if $operation == 'display'}
<div class="panelbox">
    <div class="panelbox-head">
        <A href="{php echo $this->createWebUrl('print',array('op' => 'post'))}"><i class="fa fa-plus"></i> 新增</A>
    </div>
    <form action="" method="post" class="layui-form" id="listform" enctype="multipart/form-data">
        <div class="panelbox-body">
            <div class="layui-form">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width:30px;">#</th>
                        <th>模板名称</th>
                        <th>类型</th>
                        <th>状态</th>
                        <th style="text-align:right">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $row}
                    <tr>
                        <td></td>
                        <td>{$row['title']}</td>
                        <td>{php echo $printType[$row['pcate']]}</td>
                        <td>{if $row['isdefault']}<span class="label label-success">默认</span>{/if}</td>
                        <td style="text-align:right">
                            <a href="{php echo $this->createWebUrl('print',array('op' => 'set','id' => $row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe614;</i></a>
                            <a href="{php echo $this->createWebUrl('print',array('op' => 'post', 'id' => $row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a>
                            <a href="javascript:deleteContent('{php echo $this->createWebUrl('print',array('op'=>'delete','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </form>
</div>
<script>
    function deleteContent(url){
        layer.confirm('确认删除此内容？删除后将不可恢复', {}, function(){
            location.href=url;
        });
    }
</script>
{elseif $operation == 'post'}
<style>
</style>

<div class="panelbox">
    <form action="" method="post" class="layui-form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{php echo $id}" />
        <div class="panelbox-body">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" value="{$item['title']}" name="title"/>
                    <div class="help-block">打印标题</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">模板类型</label>
                <div class="layui-input-block">
                    <select class="form-control" lay-ignore name="pcate">
                        <option value="">选择模板类型</option>
                        {loop $printType $index $row}
                        <option value="{$index}" {if $index==$item['pcate'] && $item}selected{/if}>{$row}</option>
                        {/loop}
                    </select>
                    <div class="help-block">模板类型</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数量</label>
                <div class="layui-input-block">
                    <input type="number" class="form-control" value="{$item['num']}" name="num"/>
                    <div class="help-block">打印份数</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">默认</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isdefault" value="1" {if 1==$item['isdefault']}checked{/if} title="默认打印模板">
                    <div class="help-block">设置为默认打印模板</div>
                </div>
            </div>

            <div class="layui-form-item" id="wpcont">
                <label class="layui-form-label">打印模板</label>
                <div class="layui-input-block form-inline">
                    <textarea name="wpcontent" style="width:100%; height:200px;">{$item['wpcontent']}</textarea>
                    <div class="help-block">请在word文档模板中编辑好后，复制到上面的输入框中。由于打印word文档需要4秒时间来启动，不利于实际业务操作。
                        <a href="../addons/j_hmoney/template/resources/tempfile/printdoc.doc" target="_blank">下载模板</a></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <input type="hidden" name="token" value="{$_W['token']}" />
                    <input class="layui-btn col-md-1" type="submit" name="submit"  value="保存">
                </div>
            </div>
        </div>
    </form>
</div>

<script language="javascript">
    layui.use(['layer', 'laypage', 'element','form'], function(){
        var layer = layui.layer
                ,laypage = layui.laypage
                ,element = layui.element
                ,form = layui.form;
        form.render();
        /*form.on('submit(btnsubmit)', function(data){
         var index2=layer.load(1, {shade: [0.5,'#fff']});
         $.post("{php echo $this->createWebUrl('print',array('op'=>'update'))}",data.field,function(data){
         layer.close(index2);
         console.log();
         if(!data.success){
         layer.msg(data.msg,{icon:1,time:2000});
         return false;
         }
         //location.reload();
         return false;
         },'json');
         return false;
         });*/

    });
    function showbox(obj){
        if(parseInt($(obj).val())==2){
            $("#wpcont").show();
        }else{
            $("#wpcont").hide();
        }
    }
</script>
{/if}